import 'package:flutter/material.dart' ;
import 'package:flutter/services.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:mfkb/plugin/MyBehavior.dart';
import 'package:mfkb/service/FunService.dart';
import 'package:toast/toast.dart';

class Exam extends StatefulWidget {
  @override
  _ExamState createState() => _ExamState();
}

class _ExamState extends State<Exam> {

  List data = null ;

  @override
  void initState() {
    super.initState();
    FunService().exam().then((value){
      if(value["code"] == 200){
        data = value["data"] ;
        setState(() {});
      }else{
        Toast.show(value["msg"], context) ;
      }
    }) ;
  }

  @override
  Widget build(BuildContext context) {
    return AnnotatedRegion<SystemUiOverlayStyle>(
      value: SystemUiOverlayStyle.dark ,
      child: Scaffold(
        body: Container(
          color:Color.fromARGB(255, 245, 246, 248) ,
          child: Column(
            children: <Widget>[
              Container(
                height: MediaQuery.of(context).padding.top ,
              ) ,
              Container(
                height: 45,
                child: Row(
                  children: <Widget>[
                    Container(
                      width: 17,
                      height: 17,
                      margin: EdgeInsets.only(left:ScreenUtil().setWidth(19)),
                      child: GestureDetector(
                        child: Container(
                          width: 17,
                          height: 17,
                          child: Image.asset("assets/images/back.png" , fit: BoxFit.fill,),
                        ),
                        onTap: (){
                          Navigator.of(context).pop() ;
                        },
                      ),
                    ) ,
                    Expanded(
                      child: Container(
                        child: Center(
                          child: Text("考试查询" , style: TextStyle( 
                            color: Color.fromARGB(255, 19 , 28 , 53) , 
                            fontSize: ScreenUtil().setSp(18) , 
                            fontWeight: FontWeight.bold  
                          ),), 
                        ),
                      ),
                    ) ,
                    Container(
                      height: 17 ,
                      width: 36 ,
                      margin: EdgeInsets.only(right:ScreenUtil().setWidth(15)) ,
                    ) 
                  ],
                ),
              ) ,
              Expanded(
                child: Container(
                  margin: EdgeInsets.only(top:ScreenUtil().setHeight(10) , left:ScreenUtil().setWidth(10) , right:ScreenUtil().setWidth(10) , bottom: ScreenUtil().setHeight(10)),
                  decoration: BoxDecoration(
                    color: Colors.white ,
                    borderRadius: BorderRadius.all(Radius.circular(16)) 
                  ) ,
                  child: Column(
                    children: <Widget>[
                      Container(
                        height: ScreenUtil().setHeight(60) ,
                        child: Row(
                          children: <Widget>[
                            Container(
                              width: ScreenUtil().setWidth(80),
                              margin: EdgeInsets.only(left:ScreenUtil().setWidth(14)),
                              child: Text("科目" , style: TextStyle(
                                fontSize: ScreenUtil().setSp(14) ,
                                color: Color.fromARGB(255, 121, 132, 155)
                              ),),
                            ) ,
                            Expanded(
                              child: GestureDetector(
                                child: Container(
                                  child: Center(
                                    child:  Text("教室" , style: TextStyle(
                                      fontSize: ScreenUtil().setSp(14) ,
                                      color: Color.fromARGB(255, 121, 132, 155)
                                    ),) , 
                                  ),
                                ), 
                                onTap: (){
                                },
                              ),
                            ) ,
                            Container(
                              width: ScreenUtil().setWidth(80),
                              child: Text("时间" , textAlign: TextAlign.end, style: TextStyle(
                                fontSize: ScreenUtil().setSp(14) ,
                                color: Color.fromARGB(255, 121, 132, 155)
                              )),
                              margin: EdgeInsets.only(right:ScreenUtil().setWidth(15)),
                            )
                          ],
                        ),
                      ) ,
                      Expanded(
                        child: ScrollConfiguration(
                          behavior: MyBehavior() ,
                          child: ListView(
                            padding: EdgeInsets.all(0) ,
                            children: List.generate(data == null ? 0 : data.length , (index){
                              return Container(
                                height:ScreenUtil().setHeight(56) ,
                                child: Column(
                                  children: <Widget>[
                                    Expanded(
                                      child: Container(
                                        child: Row(
                                          children: <Widget>[
                                            Container(
                                              margin: EdgeInsets.only(left:ScreenUtil().setWidth(15)),
                                              width: ScreenUtil().setWidth(100),
                                              child: Text(data[index]["className"] , style: TextStyle(
                                                fontSize: ScreenUtil().setSp(14) ,
                                                color: Color.fromARGB(255, 78, 86, 108) ,
                                                fontWeight: FontWeight.bold 
                                              ),overflow: TextOverflow.ellipsis,),
                                            ),
                                            Expanded(
                                              child:Center(
                                                child: Text(data[index]["exam_place"] , style: TextStyle(
                                                  fontSize: ScreenUtil().setSp(14) ,
                                                  color: Color.fromARGB(255, 78, 86, 108) ,
                                                  fontWeight: FontWeight.bold 
                                                )),
                                              )
                                            ) ,
                                            Container(
                                              margin: EdgeInsets.only(right:ScreenUtil().setWidth(10)),
                                              width: ScreenUtil().setWidth(100),
                                              child: Text(data[index]["exam_time"] , style: TextStyle(
                                                fontSize: ScreenUtil().setSp(12) ,
                                                color: Color.fromARGB(255, 19, 28, 53) ,
                                              ),textAlign: TextAlign.end,),
                                            )
                                          ],
                                        ),
                                      ),
                                    ) ,
                                    Container(
                                      height: ScreenUtil().setHeight(1),
                                      color: Color.fromARGB(255, 236, 237, 241) ,
                                      margin: EdgeInsets.only(left:ScreenUtil().setWidth(13) , right:ScreenUtil().setWidth(12)),
                                    ) ,
                                  ],
                                ),
                              ) ;
                            }) ,
                          ) ,
                        ) ,
                      )
                    ],
                  )
                ) ,
              )
            ],
          ),
        ),
      ),
    );
  }
}